package com.lzh.listen;

import com.lzh.client.PayClients;
import com.lzh.pojo.repVo.BaseResp;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author lkl
 * @Description
 * @Date 2022/3/30
 */

@Component
public class TravelPayListener {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    PayClients payClients;

    static final Logger logger = LoggerFactory.getLogger(TravelPayListener.class);

    @RabbitListener(queues = "tg-pay-travel")
    public void travelPay(Integer id, Channel channel, Message message) {

        try {

            logger.debug("开始进入支付！：{}" + id);
            Map map = new HashMap();
            map.put("id",id);
            BaseResp baseResp = payClients.travelPay(map);
            if(baseResp.getCode()==0){
                logger.debug("旅游支付失败了：{}" + id);
            }

            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

        } catch (IOException e) {
            e.printStackTrace();
        }

        logger.debug("支付成功！{}" + id);

    }

}
